<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\logic;

/**
 * 联系方式逻辑
 */
class Contact extends LogicBase
{
  
    /**
     * 联系方式信息编辑
     */
    public function contactEdit($data = [])
    {
         
        $validate_result = $this->validateContact->scene('edit')->check($data);
        
        if (!$validate_result) {
            
            return [RESULT_ERROR, $this->validateContact->getError()];
        }

        $jump_url = url("ContactEdit");
        
        $data['created_at'] = time();
         
        $data['updated_at'] = time();

        $result = $this->modelContact->setInfo($data);
        
        $handle_text = empty($data['id']) ? '新增' : '编辑';
        
        $result && action_log($handle_text, '联系方式' . $handle_text . '，name：' . $data['campany_name']);
        
        return $result ? [RESULT_SUCCESS, '联系方式操作成功', $jump_url] : [RESULT_ERROR, $this->modelContact->getError()];
    }

    /**
     * 获取联系方式信息
     */
    public function getContactInfo($where = [], $field = 'a.*')
    {

        $this->modelContact->alias('a');
        
        $where['a.' . DATA_STATUS_NAME] = ['neq', DATA_DELETE];

        return $this->modelContact->getInfo($where, $field);
    }
    
   
    /**
     * 联系方式删除
     */
    public function contactDel($where = [])
    {
        
        $result = $this->modelContact->deleteInfo($where);
        
        $result && action_log('删除', '联系方式删除，where：' . http_build_query($where));
        
        return $result ? [RESULT_SUCCESS, '联系方式删除成功'] : [RESULT_ERROR, $this->modelContact->getError()];
    }
}
